package com.drg.center.controller;

import cn.hutool.core.lang.tree.Tree;
import com.drg.center.entity.param.ResourcesAddDTO;
import com.drg.center.entity.param.ResourcesEditDTO;
import com.drg.center.entity.result.SysResourcesVO;
import com.guaike.core.entity.result.Result;
import com.drg.center.service.SysResourcesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * @Author: zhangxilin
 * @Date: 2024/5/21
 */
@RestController
@RequestMapping("/res")
@Api(tags = "系统-资源接口组")
public class SysResourcesController {

    @Autowired
    private SysResourcesService sysResourcesService;

    @GetMapping("/findTree")
    @ApiOperation(value = "资源树")
    public Result<List<Tree<Long>>> findTree(@ApiParam("系统编号") @RequestParam("sysCode") String sysCode,
                                             @ApiParam("只包含菜单标识") @RequestParam("onlyMenu") Boolean onlyMenu){
        return sysResourcesService.findTree(sysCode, onlyMenu);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "详情")
    public Result<SysResourcesVO> detail(@ApiParam("ID") @RequestParam("id") Long id){
        return sysResourcesService.detail(id);
    }


    @PostMapping("/add")
    @ApiOperation(value = "添加")
    public Result<Boolean> add(@Valid @RequestBody ResourcesAddDTO param){
        return sysResourcesService.add(param);
    }

    @PostMapping("/edit")
    @ApiOperation(value = "编辑")
    public Result<Boolean> edit(@Valid @RequestBody ResourcesEditDTO param){
        return sysResourcesService.edit(param);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除")
    public Result<Boolean> delete(@ApiParam("ID") @RequestParam("id") Long id){
        return sysResourcesService.delete(id);
    }
}
